package com.shujia.mapreduce;

import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.net.Socket;

public class Demo3ApplicationMaster {

    public static void main(String[] args) throws Exception {

        //线程对象
        Task task = new Task();

        //启动线程
        //task.start();

        Socket localhost = new Socket("localhost", 8989);

        //获取输出流
        OutputStream outputStream = localhost.getOutputStream();

        //对象输出流
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);

        //发送task
        objectOutputStream.writeObject(task);

        objectOutputStream.flush();

    }
}

/**
 * 类需要实现Serializable接口才能被序列化，才能在网络中传输
 */

/**
 * map task和reduce task本质上是一个线程对象，这个对象中包含了用户自己定义的代码逻辑，数据排序方式、分区方式、读数据方式
 */
class Task extends Thread implements Serializable {
    @Override
    public void run() {

        for (int i = 0; i < 100; i++) {
            System.out.println(i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
